package com.accompany.api.presenter;

import com.accompany.api.bean.OrderComment;
import com.accompany.api.category.OrderCommCategory;
import com.accompany.utils.RetrofitUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class OrderCommentPresenter implements OrderCommCategory.Presenter{
    private OrderCommCategory.View view;

    public OrderCommentPresenter(OrderCommCategory.View view) {
        this.view = view;
    }

    // 已完成订单的评论
    @Override
    public void getOrderComment(String mToken, String orderId,long acdId) {
        RetrofitUtil.getInstance().getmService().get_order_comment(mToken,orderId,acdId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    OrderComment orderComment = gson.fromJson(result, OrderComment.class);
                    view.getOrderComment(orderComment);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
}
